package jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

import static java.lang.Class.forName;

/**
 * JDBC java数据库链接
 * */
public class JDBCDemo1 {
    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            Connection connection=DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
                    "root",
                    "root"
            );
            System.out.println("链接数据库成功");
            Statement statement =connection.createStatement();
            String sql="CREATE TABLE user1( " +
                    "    id INT PRIMARY KEY AUTO_INCREMENT, " +
                    "    username VARCHAR(32), " +
                    "    password VARCHAR(32), " +
                    "    nickname VARCHAR(32), " +
                    "    age INT(3) " +
                    ")";
            statement.execute(sql);//execute:执行
            System.out.println("创建完成");
            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
